#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

DEPTH		= ../../..
topsrcdir	= @top_srcdir@
srcdir		= @srcdir@
VPATH		= @srcdir@

include $(DEPTH)/config/autoconf.mk

MODULE		= xpconnect

LIBRARY_NAME    = xpconnect_s
FORCE_STATIC_LIB = 1
LIBXUL_LIBRARY = 1
EXPORTS = \
		qsObjectHelper.h \
		xpcObjectHelper.h \
		xpcpublic.h \
		XPCJSMemoryReporter.h \
		dombindings.h \
		dombindings_gen.h \
		GeneratedEvents.h

CPPSRCS		= \
		nsScriptError.cpp \
		nsXPConnect.cpp \
		XPCCallContext.cpp \
		XPCComponents.cpp \
		XPCContext.cpp \
		XPCConvert.cpp \
		XPCDebug.cpp \
		XPCException.cpp \
		XPCJSID.cpp \
		XPCJSRuntime.cpp \
		XPCLocale.cpp \
		XPCLog.cpp \
		XPCMaps.cpp \
		XPCModule.cpp \
		XPCRuntimeService.cpp  \
		XPCStack.cpp \
		XPCString.cpp \
		XPCJSContextStack.cpp \
		XPCThrower.cpp \
		XPCWrappedJS.cpp \
		XPCVariant.cpp \
		XPCWrappedJSClass.cpp \
		XPCWrappedNative.cpp \
		XPCWrappedNativeInfo.cpp \
		XPCWrappedNativeJSOps.cpp \
		XPCWrappedNativeProto.cpp \
		XPCWrappedNativeScope.cpp \
		XPCJSWeakReference.cpp \
		XPCWrapper.cpp \
		XPCQuickStubs.cpp \
		dom_quickstubs.cpp \
		dombindings.cpp \
		DictionaryHelpers.cpp \
		GeneratedEvents.cpp \
		$(NULL)

include $(topsrcdir)/config/config.mk

LOCAL_INCLUDES = \
		-I$(srcdir)/../wrappers \
		-I$(srcdir)/../loader \
		-I$(topsrcdir)/caps/include \
		-I$(topsrcdir)/content/base/src \
		-I$(topsrcdir)/content/events/src \
		-I$(topsrcdir)/content/html/content/src \
		-I$(topsrcdir)/content/html/document/src \
		-I$(topsrcdir)/content/svg/content/src \
		-I$(topsrcdir)/layout/style \
		-I$(topsrcdir)/layout/base \
		-I$(topsrcdir)/dom/base \
		-I$(topsrcdir)/xpcom/ds \
		$(NULL)

SHARED_LIBRARY_LIBS = \
  ../loader/$(LIB_PREFIX)jsloader_s.$(LIB_SUFFIX) \
  ../wrappers/$(LIB_PREFIX)xpcwrappers_s.$(LIB_SUFFIX) \
  $(NULL)

include $(topsrcdir)/config/rules.mk

DEFINES += \
  -DJSFILE \
  -DJS_THREADSAFE \
  -DEXPORT_XPC_API \
  -DNO_NSPR_10_SUPPORT \
  $(NULL)

ifdef MOZ_JSDEBUGGER
DEFINES += -DMOZ_JSDEBUGGER
endif

ifeq ($(OS_ARCH),WINNT)
ifndef GNU_CXX
ifeq (,$(filter-out 1200 1300 1310,$(_MSC_VER)))
# whole program optimization and precompiled headers are incompatible
ifeq (,$(findstring GL,$(CXXFLAGS)))
# use pre-compiled headers
CXXFLAGS	+= -YX -Fp$(LIBRARY_NAME).pch
# precompiled headers require write access to .pch which breaks -j builds
.NOTPARALLEL:
endif
endif
endif
endif

nsXPConnect.$(OBJ_SUFFIX): dom_quickstubs.h

XPCJSRuntime.$(OBJ_SUFFIX): dom_quickstubs.h

dom_quickstubs.h: dom_quickstubs.cpp

dom_quickstubs.cpp: $(srcdir)/dom_quickstubs.qsconf \
                    $(srcdir)/qsgen.py \
                    $(LIBXUL_DIST)/sdk/bin/header.py \
                    $(LIBXUL_DIST)/sdk/bin/xpidl.py \
                    $(DEPTH)/js/src/js-confdefs.h
	$(PYTHON) $(topsrcdir)/config/pythonpath.py \
	  $(PLY_INCLUDE) \
	  -I$(LIBXUL_DIST)/sdk/bin \
	  $(srcdir)/qsgen.py \
	  --idlpath=$(DEPTH)/dist/idl \
	  --header-output dom_quickstubs.h \
	  --stub-output dom_quickstubs.cpp \
	  --makedepend-output $(MDDEPDIR)/dom_qsgen.pp \
	  $(ENABLE_TRACEABLE_FLAGS) \
	  $(srcdir)/dom_quickstubs.qsconf

dombindings.$(OBJ_SUFFIX): dombindings_gen.h \
                           dombindings_gen.cpp

dombindings_gen.h: $(srcdir)/dombindings.conf \
                   $(srcdir)/dombindingsgen.py \
                   $(srcdir)/codegen.py \
                   $(LIBXUL_DIST)/sdk/bin/header.py \
                   $(LIBXUL_DIST)/sdk/bin/xpidl.py \
                   $(DEPTH)/js/src/js-confdefs.h
	$(PYTHON) $(topsrcdir)/config/pythonpath.py \
	  $(PLY_INCLUDE) \
	  -I$(LIBXUL_DIST)/sdk/bin \
	  $(srcdir)/dombindingsgen.py \
	  --idlpath=$(DEPTH)/dist/idl \
	  --header-output dombindings_gen.h \
	  $(srcdir)/dombindings.conf

exports:: dombindings_gen.h

dombindings_gen.cpp: $(srcdir)/dombindings.conf \
                     $(srcdir)/dombindingsgen.py \
                     $(srcdir)/codegen.py \
                     $(LIBXUL_DIST)/sdk/bin/header.py \
                     $(LIBXUL_DIST)/sdk/bin/xpidl.py \
                     $(DEPTH)/js/src/js-confdefs.h
	$(PYTHON) $(topsrcdir)/config/pythonpath.py \
	  $(PLY_INCLUDE) \
	  -I$(LIBXUL_DIST)/sdk/bin \
	  $(srcdir)/dombindingsgen.py \
	  --idlpath=$(DEPTH)/dist/idl \
	  --stub-output dombindings_gen.cpp \
	  --makedepend-output $(MDDEPDIR)/dombindingsgen.pp \
	  $(srcdir)/dombindings.conf

DictionaryHelpers.$(OBJ_SUFFIX): DictionaryHelpers.cpp

DictionaryHelpers.h: DictionaryHelpers.cpp

DictionaryHelpers.cpp: $(srcdir)/dictionary_helper_gen.conf \
                       event_impl_gen.conf \
                       $(srcdir)/dictionary_helper_gen.py \
                       $(srcdir)/codegen.py \
                       $(LIBXUL_DIST)/sdk/bin/header.py \
                       $(LIBXUL_DIST)/sdk/bin/xpidl.py \
                       $(DEPTH)/js/src/js-confdefs.h
	$(PYTHON) $(topsrcdir)/config/pythonpath.py \
	  $(PLY_INCLUDE) \
	  -I$(LIBXUL_DIST)/sdk/bin \
	  $(srcdir)/dictionary_helper_gen.py \
	  -I $(DEPTH)/dist/idl \
	  --header-output DictionaryHelpers.h \
	  --stub-output DictionaryHelpers.cpp \
	  --makedepend-output $(MDDEPDIR)/dictionary_helper_gen.pp \
	  $(srcdir)/dictionary_helper_gen.conf \
	  event_impl_gen.conf

GeneratedEvents.$(OBJ_SUFFIX): GeneratedEvents.h \
                               GeneratedEvents.cpp

event_impl_gen.conf : $(srcdir)/event_impl_gen.conf.in
	$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(DEFINES) $(ACDEFINES) $^ > event_impl_gen.conf

GeneratedEvents.h: $(srcdir)/dictionary_helper_gen.conf \
                   event_impl_gen.conf \
                   $(srcdir)/dictionary_helper_gen.py \
                   $(srcdir)/event_impl_gen.py \
                   $(srcdir)/codegen.py \
                   $(LIBXUL_DIST)/sdk/bin/header.py \
                   $(LIBXUL_DIST)/sdk/bin/xpidl.py \
                   $(DEPTH)/js/src/js-confdefs.h
	$(PYTHON) $(topsrcdir)/config/pythonpath.py \
	  $(PLY_INCLUDE) \
	  -I$(LIBXUL_DIST)/sdk/bin \
	  $(srcdir)/event_impl_gen.py \
	  -I $(DEPTH)/dist/idl \
	  --header-output GeneratedEvents.h \
	  event_impl_gen.conf

GeneratedEvents.cpp: DictionaryHelpers.h \
                     $(srcdir)/dictionary_helper_gen.conf \
                     event_impl_gen.conf \
                     $(srcdir)/dictionary_helper_gen.py \
                     $(srcdir)/event_impl_gen.py \
                     $(srcdir)/codegen.py \
                     $(LIBXUL_DIST)/sdk/bin/header.py \
                     $(LIBXUL_DIST)/sdk/bin/xpidl.py \
                     $(DEPTH)/js/src/js-confdefs.h
	$(PYTHON) $(topsrcdir)/config/pythonpath.py \
	  $(PLY_INCLUDE) \
	  -I$(LIBXUL_DIST)/sdk/bin \
	  $(srcdir)/event_impl_gen.py \
	  -I $(DEPTH)/dist/idl \
	  --header-output GeneratedEvents.h \
	  --stub-output GeneratedEvents.cpp \
	  --makedepend-output $(MDDEPDIR)/event_impl_gen.pp \
	  event_impl_gen.conf

_EXTRA_EXPORT_FILES = \
  DictionaryHelpers.h \
  $(NULL)

libs:: $(_EXTRA_EXPORT_FILES)
	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/dist/include

GARBAGE += \
		dom_quickstubs.h \
		dom_quickstubs.cpp \
		dombindings_gen.h \
		dombindings_gen.cpp \
		DictionaryHelpers.h \
		DictionaryHelpers.cpp \
		GeneratedEvents.h \
		GeneratedEvents.cpp \
		event_impl_gen.conf \
		xpidl_debug \
		$(MDDEPDIR)/dom_qsgen.pp \
		$(MDDEPDIR)/dombindingsgen.pp \
		$(MDDEPDIR)/dictionary_helper_gen.pp \
		$(MDDEPDIR)/event_impl_gen.pp \
		$(wildcard $(topsrcdir)/other-licenses/ply/ply/*.pyc) \
		$(NULL)

DEFINES += -D_IMPL_NS_LAYOUT
